#!/usr/bin/env python 
# -*- coding:utf-8 -*-
# import JSON
# from urllib import parse, request
#
#
# # def getOpenRoomList():
# textmod = {'userId': '12410', 'chatId': '10062'}
# textmod = parse.urlencode(textmod)
# header_dict = {
#     'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko',
#     'token': '61ea92ab32003afb44ab5f8'}
# url = 'http://192.168.62.35:30410/nlogin/'
# req = request.Request(url='%s%s%s' % (url, '?', textmod), headers=header_dict)
# res = request.urlopen(req)
# ret = res.read()
# jsonData = JSON.loads(ret)
# print(jsonData)
# resultcode = jsonData['ret']
# if (0 == resultcode):
#     print("get open room list succ!")
# else:
#     print("get open room list failed!")


# coding:utf-8

__author__ = 'lanzhi'

import sys
import time
from urllib import request

# reload(sys)
# sys.setdefaultencoding('utf8')
appkey = 'xxx'
# 生产
# appsecret = 'xxx'
# uat
appsecret = 'xxx'


def send_request(url, argv):
    headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
               'X-Requested-With': 'XMLHttpRequest',
               'Connection': 'keep-alive',
               'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36',
               }
    dict = '{"matchAny":"false","name":%s}' % argv
    url = "%s?filter=%s&pageSize=25&startIndex=0" % (url, str(dict))
    # url = 'https://cscentral-eu.amazon.com/call-center-manager/entity-search/profiles?filter=%7B%22matchAny%22:false,%22name%22:%22TAM_UK_CNEN_2C1E_MATFBA%22%7D&pageSize=25&startIndex=0'
    print(url)
    http_request = request.Request(url, headers=headers)
    response = request.urlopen(http_request)
    return response.read()
    # except error.URLError as e:
    #     print('URLError：' + e.reason)
    # except error.HTTPError as e:
    #     print('HTTPError：' + e.code)
    # if e.reason == 'Not Found':
    #     Case = 'connect'
    #     print([Case, 'Page Not Found!!'])
    # else:
    #     print('connect is OK ~!')


if __name__ == '__main__':
    print('-----------start----------------')
    url = 'https://cscentral-eu.amazon.com/call-center-manager/entity-search/profile'
    response = send_request(url, sys.argv)
    time.sleep(0.01)
    print(response)

    print("------finish--------------")
